package com.agy.filemanager.configuration;


import org.apache.hadoop.fs.FileSystem;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.net.URI;
import java.net.URISyntaxException;

@Configuration
@PropertySource("classpath:resource/hdfs.properties")
public class HDFSConfig {

    @Value("${HDFS_URI}")
    private String uri;
    @Value("${USER}")
    private String user;
    /**
     * 获取hdfs配置Configuration类
     * @return
     */
    @Bean("configuration")
    public org.apache.hadoop.conf.Configuration getConfiguration(){
        return new org.apache.hadoop.conf.Configuration();
    }

    /**
     * 获取hdfsjava客户端 FileSystem
     * @param configuration
     * @return
     * @throws Exception
     */
    @Bean
    public FileSystem getFileSystem(org.apache.hadoop.conf.Configuration configuration) throws Exception {
        FileSystem fs = FileSystem.get(new URI(uri), configuration, user);
        return fs;
    }

}
